<?php
class Relate extends Model{
	public $_table = 'tpl_block';

	public function relateData($data_id,$tpl_id){
		$sql = "select * from {$this->_table} where did=".$data_id." and tid=".$tpl_id;
		$d = $this->getOne($sql);
		if(empty($d)){
			$arr = array(
				'`did`'=>$data_id,
				'`tid`'=>$tpl_id,
			);
			$this->add($arr);
		}
	}	

	/* @param $data_id 数据ID
	 *
	 */
	public function syncTpl($data_id){
		$tpl = Core::getInstance()->app_load_class('Template');
		$sql = "select * from {$this->_table} where `did`=".intval($data_id);
		$data = $this->all($sql);
		foreach($data as $k=>$v){
			if($v['tid']) $tpl->updateHtml($v['tid']);
		}
	}
}
